Skip to content

iOS 向けに AudioTrackSink を追加する#128

Merged
zztkm merged 21 commits into
feature/m143.7499from
feature/ios-audio-track-sink
Dec 11, 2025
Merged

iOS 向けに AudioTrackSink を追加する#128
zztkm merged 21 commits into
feature/m143.7499from
feature/ios-audio-track-sink

Conversation

@zztkm

@zztkm zztkm commented Nov 18, 2025

Copy link
Copy Markdown
Contributor

No description provided.

@zztkm

zztkm commented Dec 8, 2025

Copy link
Copy Markdown
Contributor Author

!haiku レビューして

@github-actions

This comment was marked as resolved.

@zztkm

zztkm commented Dec 10, 2025

Copy link
Copy Markdown
Contributor Author

!haiku レビューして

@github-actions

This comment was marked as resolved.

@zztkm zztkm changed the title [WIP] iOS 向けに AudioTrackSink を追加する iOS 向けに AudioTrackSink を追加する Dec 10, 2025
@zztkm

zztkm commented Dec 10, 2025

Copy link
Copy Markdown
Contributor Author

!haiku 以下の観点でレビューして

  • typo や文章におかしな点がないか
  • patch と説明ファイル (md) に乖離がないか

@github-actions

This comment was marked as resolved.

steps:
- uses: actions/checkout@v5
- name: Select Xcode 16.1
- name: Select Xcode 26.0

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正が漏れていたのでついでに対応しました

@zztkm zztkm requested a review from melpon December 10, 2025 06:07
Comment thread patches/ios_audio_track_sink.patch Outdated
+
+/**
+ * このアダプターが公開するネイティブの AudioTrackSinkInterface。呼び出しは生成時に
+ * 渡された RTCAudioTrackSink へ変換されます。このポインタは非安全で、このクラスが所有します。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

「呼び出しは生成時に渡された RTCAudioTrackSink へ変換されます。」の意味が全く理解できないので、もうちょっとコメント考えてほしいです。
「このポインタは非安全で、このクラスが所有します。」も、非安全という書き方もあまり見かけないし、非安全がどういう意味なのかが分からないです。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

実態は AudioTrackSinkAdapter を見ればわかると思ったので、ここもコメント削除します

Comment thread patches/ios_audio_track_sink.patch Outdated
+ * webrtc::AudioTrackSinkInterface は WebRTC の音声処理で使われ、このアダプターが
+ * その呼び出しを生成時に渡された RTCAudioTrackSink へ橋渡しします。
+ */
+@interface RTCAudioTrackSinkAdapter : NSObject

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

このクラスは公開する必要なさそうなので、このファイルは不要そうに見えます

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

削除しました

Comment thread patches/ios_audio_track_sink.patch Outdated
- (instancetype)init NS_UNAVAILABLE;

-/** The audio source for this audio track. */
+/** このオーディオトラックの音声ソース。 */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここは変更する必要なさそう

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

戻しました

Comment thread patches/ios_audio_track_sink.md Outdated
}

func preferredNumberOfChannels() -> Int {
return 1 // 例: モノラルで受けたい場合。指定しなければ -1 を返す。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

指定しなければ -1 を返す

「実装しなければ -1 を返すデフォルト実装が使われる」
「特にチャンネル数を指定しない場合は -1 を返しても構わない」
あたりかな。ただ後者の書き方だとこの関数の実装をサボれることが分からないので、前者寄りの書き方が良さそうな気がします。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ありがとうございます。前者の書き方に修正します。

Comment thread patches/ios_audio_track_sink.md Outdated
Comment thread patches/ios_audio_track_sink.md Outdated

### パッチ実装のポイント

- `RTCAudioTrackSinkAdapter` は `AudioTrackSinkInterface` を実装し、`OnData` で受け取った PCM を `NSData` にコピーして `RTCAudioTrackSink#onData` に渡す。コールバックはネイティブ音声スレッドで呼ばれるため、重い処理は別スレッドへ委譲する必要があることに注意。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RTCAudioTrackSinkAdapterAudioTrackSinkInterface を実装し

AudioTrackSinkInterface を実装しているのは AudioTrackSinkAdapter のはず。

RTCAudioTrackSink#onData に渡す

# で繋ぐのは Java の書き方なので、Objective-C 的には「RTCAudioTrackSinkonData:bitsPerSample:sampleRate:numberOfChannels:numberOfFrames: に渡す」かな。

別スレッドへ委譲する必要がある、に関してはパッチ実装のポイントではないので不要そう。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

別スレッドへ〜の説明はドキュメント下の注意点の説明の部分に移動させました。

Comment thread patches/ios_audio_track_sink.md Outdated
Comment thread patches/ios_audio_track_sink.patch Outdated
+
+/**
+ * このアダプター生成時に渡された Objective-C の音声トラックシンク。
+ * webrtc::AudioTrackSinkInterface への呼び出しはここへ変換されて渡されます。

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

この行のコメント理解するのにめっちゃ時間掛かったので、直せそうなら直して欲しいかも。
そもそもこの説明を書く必要あるかが疑問。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

header file の方で使われ方について実装も交えたコメントをわざわざ書くのもおかしいと思ったので、説明を削除しました

+ return static_cast<int>([sink preferredNumberOfChannels]);
+ }
+ return -1;
+ }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なんかインデントおかしい気がする

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正しました。(上の int Num ~ の先頭に合わせました

zztkm and others added 4 commits December 11, 2025 07:23
Co-authored-by: melpon <shigemasa7watanabe+github@gmail.com>
Co-authored-by: melpon <shigemasa7watanabe+github@gmail.com>
Comment thread patches/ios_audio_track_sink.md Outdated
+ if ([sink respondsToSelector:@selector(preferredNumberOfChannels)]) {
+ return static_cast<int>([sink preferredNumberOfChannels]);
+ }
+ return -1;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

インデントが2スペースであることを考えると、このあたりのインデントも直す必要がありそう。
というより、depot_tools にパスを通してから git cl format しても良いと思います。

@zztkm zztkm Dec 11, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PATH を通したあとに、

python3 run.py revert --patch ios_audio_track_sink.patch

cd _source/ios_sdk/webrtc/src

# 新しいファイルは一度ステージングする
# git add sdk/objc/api/RTCAudioTrackSinkAdapter.mm

git cl format [file 指定]

# ステージング解除
# git restore --staged sdk/objc/api/RTCAudioTrackSinkAdapter.mm

python3 run.py diff ios_sdk > patches/ios_audio_track_sink.patch

この手順でフォーマットをかけて、パッチを更新してみます。
単純に git cl format を実行すると全く関係のないファイルまでフォーマットされたので、とりあえず必要なファイルにだけフォーマットをあてるスタイルです。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

9816cba で git cl format しました。

Co-authored-by: melpon <shigemasa7watanabe+github@gmail.com>
Comment thread patches/ios_audio_track_sink.md Outdated
Co-authored-by: melpon <shigemasa7watanabe+github@gmail.com>

@melpon melpon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

よさそう

@zztkm zztkm merged commit 2ed20b6 into feature/m143.7499 Dec 11, 2025
@zztkm zztkm deleted the feature/ios-audio-track-sink branch December 11, 2025 09:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants